﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using Telerik.Web.UI;

public partial class Front_UserControl_RecentDeal : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //setSecureProtocol(false);
        if (!IsPostBack)
        {


            try
            {
                if (Request.Cookies["CityName"] != null)
                {

                    LblCityName.Text = Request.Cookies["CityName"].Value.ToString();
                    var Recentdeal1 = new DealesDataContext();
                    var RecentDealquery1 = Recentdeal1.Select_RecentDealByCityID(Convert.ToInt32(Request.Cookies["CityID"].Value.ToString()));
                    RecentDeal.DataSource = RecentDealquery1;
                    RecentDeal.DataBind();

                }
            }
            catch
            {
            }
        }

    }
    public void setSecureProtocol(bool bSecure)
    {
        string redirectUrl = null;

        // if we want HTTPS and it is currently HTTP
        if (bSecure && !Request.IsSecureConnection)
            redirectUrl = Request.Url.ToString().Replace("http:", "https:");

        else

            // if we want HTTP and it is currently HTTPS
            if (!bSecure && Request.IsSecureConnection) redirectUrl = Request.Url.ToString().Replace("https:", "http:");

        //else

        // in all other cases we don't need to redirect

        // check if we need to redirect, and if so use redirectUrl to do the job
        if (redirectUrl != null)

            Response.Redirect(redirectUrl);

    }
    protected void btnName_OnClick(object sender, EventArgs e)
    {
        LinkButton lnkbtn = (LinkButton)sender;
        Response.Redirect("~/Default.aspx?RecentDealID=" + lnkbtn.CommandArgument);

    }

    protected void Image1_OnClick(object sender, EventArgs e)
    {
        ImageButton imgbtn = (ImageButton)sender;
        Response.Redirect("~/Default.aspx?RecentDealID=" + imgbtn.CommandArgument);
    }
    protected string TrimDescription(string description)
    {
        if (!string.IsNullOrEmpty(description) && description.Length > 100)
        {
            return string.Concat(description.Substring(0, 100), "...");
        }
        return description;
    }
}
